﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Ponei
{
    class Ponei : GameObject
    {

       // Texture2D sprite;
        int playerId;
        int health;
        int direction;
        animacao _animacao_atual, andando, coice;
        

       // Boolean ativo;

        //Vector2 position;
       

        /// <summary>
        /// Cria um novo ponei.
        /// </summary>
        /// <param name="sprite"> Gráfico do ponei</param>
        /// <param name="playerId">ID do jogador (player '1' ou player '2')</param>
        public Ponei(GameWindow Window, Texture2D sprite, int playerId)
            :base(sprite, Window)
        {

            this.escala = 0.5f;

            _animacao_atual = new animacao();

            #region andando
            this.andando = new animacao();
            andando.nome = "andando";
            andando.qtd_quadros = 4;
            andando.quadro_atual = 0;
            andando.quadros_seg = 10;
            andando.Y = 0;
            andando.ativa = false;

            andando.quadro_X = 778;
            andando.quadro_Y = 1146;
            #endregion

            #region coice
            this.coice = new animacao();
            coice.nome = "coice";
            coice.qtd_quadros = 4;
            coice.quadro_atual = 0;
            coice.quadros_seg = 10;
            coice.Y = 1;
            coice.ativa = false;

            coice.quadro_X = 778;
            coice.quadro_Y = 1146;
            #endregion

            _animacao_atual = andando;

            this.playerId = playerId;
            posicao.X = 250;
            posicao.Y = 0;
            

        }

        /// <summary>
        /// Método update da classe
        /// </summary>
        /// <param name="gameTime"> Tempo do sistema </param>
        /// <param name="keyboard"> Teclado Atual</param>
        /// <param name="old_keyboard"> Teclado Anterior </param>


        public void Update(GameTime gameTime, KeyboardState keyboard, KeyboardState old_keyboard)
        {

            //this.colisao = new Rectangle((int)posicao.X, (int)posicao.Y, _animacao.quadro_X, _animacao.quadro_Y);
            

            switch (this.playerId)
            {
                    //Player 1
                case 1:
                    {
                        #region teclas de movimento
                           
                            if(keyboard.IsKeyDown(Keys.W))
                            {
                                this.doMove(0, -10f);
                              //Fazer pulo
                            }
                            if(keyboard.IsKeyDown(Keys.A))
                            {
                                this.doMove(3, -10f);
                                base.direita = false;
                                _animacao_atual = andando;
                                _animacao_atual.ativa = true;
                            }
                            if(keyboard.IsKeyDown(Keys.S))
                            {
                                this.doMove(2, 10f);
                            }
                            if (keyboard.IsKeyDown(Keys.D))
                            {
                                this.doMove(1, 10f);
                                base.direita = true ;
                                _animacao_atual = andando;
                                _animacao_atual.ativa = true;
                            }
                            if (keyboard.IsKeyDown(Keys.Q))
                            {
                                _animacao_atual = coice;
                                _animacao_atual.ativa = true;
                            }
                            

                        #endregion

                        break;
                    }

                    //Player 2
                case 2:
                    {
                        #region teclas de movimento

                        if (keyboard.IsKeyDown(Keys.Up))
                        {
                            this.doMove(0, -10f);
                            //Fazer pulo
                        }
                        if (keyboard.IsKeyDown(Keys.Left))
                        {
                            this.doMove(3, -10f);
                            base.direita = false;
                            _animacao_atual = andando;
                            _animacao_atual.ativa = true;
                        }
                        if (keyboard.IsKeyDown(Keys.Down))
                        {
                            this.doMove(2, 10f);
                        }
                        if (keyboard.IsKeyDown(Keys.Right))
                        {
                            this.doMove(1, 10f);
                            base.direita = true;
                            _animacao_atual = andando;
                            _animacao_atual.ativa = true;
                        }

                        if (keyboard.IsKeyDown(Keys.PageDown))
                        {
                            _animacao_atual = coice;
                            _animacao_atual.ativa = true;
                        }

                        #endregion

                        break;
                    }

                default:
                    break;
            }


            if ((keyboard.IsKeyUp(Keys.A) && old_keyboard.IsKeyDown(Keys.A)) || (keyboard.IsKeyUp(Keys.D) && old_keyboard.IsKeyDown(Keys.D)))
            {
                _animacao_atual.ativa = false;
            }

            if ((keyboard.IsKeyUp(Keys.Left) && old_keyboard.IsKeyDown(Keys.Left)) || (keyboard.IsKeyUp(Keys.Right) && old_keyboard.IsKeyDown(Keys.Right)))
            {
                _animacao_atual.ativa = false;
            }


        }


        

        /// <summary>
        /// Desenhador
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch, this._animacao_atual);     
        }

    }
}
